<template>
  <div class="screen-wrapper">
    <div class="data-screen">
    <!-- 头部标题区域 -->
    <header class="screen-header">
      <div class="header-content">
        <h1 class="main-title">树岛数据监控大屏</h1>
        <div class="header-info">
          <button class="back-btn" @click="goBack">
            ← 返回
          </button>
          <span class="current-time">{{ currentTime }}</span>
        </div>
      </div>
    </header>

    <!-- 主要内容区域 -->
    <main class="screen-content">
      <!-- 左侧图表区域 -->
      <aside class="left-charts">
        <!-- 行业分布 -->
        <BarChart 
          title="帖子分布"
          :data="industryData"
          bar-color="linear-gradient(180deg, #00d4ff, #0099cc)"
        />
        
        <!-- 省份分布 -->
        <BarChart 
          title="拦截情况"
          :data="provinceData"
          bar-color="linear-gradient(180deg, #00ff88, #00cc66)"
        />
        
        <!-- 三个环形图 -->
        <div class="pie-charts-container">
          <div class="pie-charts-grid">
            <PieChart 
              title="年龄分布"
              :data="ageData"
            />
            <PieChart 
              title="职业分布"
              :data="jobData"
            />
            <PieChart 
              title="兴趣分布"
              :data="interestData"
            />
          </div>
        </div>
      </aside>

      <!-- 中间数字卡片区域 -->
      <div class="center-content">
        <!-- 组合数字卡片 -->
        <CombinedNumberCard 
          :left-number="980"
          left-title="8月份发帖人数"
          :right-number="1200"
          right-title="9月份发帖人数"
          color="#ffff00"
        />
        
        <!-- 科技旋转木马 -->
        <TechCarousel 
          title="功能导航中心"
          :items="carouselItems"
          :auto-rotate="true"
          :rotate-speed="3000"
        />
      </div>
      <!-- 右侧区域 -->
      <div class="right-content">
        <!-- 时间趋势图 -->
        <LineChart 
          title="活跃度趋势"
          :android-data="timeAndroidData"
          :ios-data="timeIosData"
          :x-labels="timeLabels"
        />
        
        <!-- 省份TOP -->
        <BarChart 
          title="用户数量"
          :data="topProvinceData"
          bar-color="linear-gradient(180deg, #00d4ff, #0099cc)"
        />
        
        <!-- 一线城市情况 -->
        <RosePieChart 
          title="城市分布情况"
          :data="cityData"
        />
      </div>
    </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import BarChart from '../components/chart_components/BarChart.vue'
import PieChart from '../components/chart_components/PieChart.vue'
import CombinedNumberCard from '../components/chart_components/CombinedNumberCard.vue'
import RosePieChart from '../components/chart_components/RosePieChart.vue'
import LineChart from '../components/chart_components/LineChart.vue'
import TechCarousel from '../components/chart_components/TechCarousel.vue'

const router = useRouter()
// 响应式数据
const currentTime = ref('')

// 行业分布数据
const industryData = ref([
  { label: '每日小记', value: 142 },
  { label: '校园活动', value: 146 },
  { label: '失物招领', value: 85 },
  { label: '心理治愈', value: 80 },
  { label: '学习资源', value: 96 },
  { label: '智能食堂', value: 132 },
  { label: '活动策划', value: 160 }
])

// 省份分布数据
const provinceData = ref([
  { label: '每日小记', value: 38 },
  { label: '校园活动', value: 42 },
  { label: '失物招领', value: 15 },
  { label: '心理治愈', value: 18 },
  { label: '学习资源', value: 31 },
  { label: '智能食堂', value: 28 },
  { label: '活动策划', value: 58 }
])

// 年龄分布数据
const ageData = ref([
  { label: '18-19岁', value: 30, color: '#00d4ff' },
  { label: '20-21岁', value: 40, color: '#00ff88' },
  { label: '21岁以上', value: 30, color: '#5470c6' }
])

// 职业分布数据
const jobData = ref([
  { label: '职工', value: 20, color: '#00d4ff' },
  { label: '学生', value: 61, color: '#4ecdc4' },
  { label: '老师', value: 18, color: '#91cc75' }
])

// 兴趣分布数据
const interestData = ref([
  { label: '活动策划', value: 18, color: '#00d4ff' },
  { label: '失物招领', value: 30, color: '#00ff88' },
  { label: '校园活动', value: 22, color: '#ff6b6b' },
  { label: '心理治愈', value: 30, color: '#ffa726' }
])

// 时间趋势数据
const timeAndroidData = ref([32, 52, 72, 31, 51, 88, 42])
const timeIosData = ref([35, 55, 82,32, 42, 65, 62, 24])
const timeLabels = ref(['1','2', '3', '4', '5', '6', '7'])

// 省份TOP数据
const topProvinceData = ref([
  { label: '浙江', value: 350 },
  { label: '上海', value: 180 },
  { label: '江苏', value: 256 },
  { label: '广东', value: 372 },
  { label: '北京', value: 150 },
  { label: '深圳', value: 260 },
  { label: '安徽', value: 340 },
  { label: '四川', value: 580 }
])

// 一线城市数据
const cityData = ref([
  { label: '四川', value: 580, color: '#00d4ff' },
  { label: '安徽', value: 340, color: '#00ff88' },
  { label: '广东', value: 372, color: '#ff6b6b' },
  { label: '浙江', value: 350, color: '#ffa726' },
  { label: '深圳', value: 260, color: '#91cc75' }
])

// 科技旋转木马数据
const carouselItems = ref([
  { 
    label: '中国数据传输', 
    value: '实时', 
    action: () => router.push('/chinaMap')
  },
  { 
    label: '系统监控', 
    value: '在线', 
    action: () => console.log('系统监控功能')
  },
  { 
    label: '用户管理', 
    value: '5.2K', 
    action: () => router.push('/users')
  },
  { 
    label: '报表生成', 
    value: '自动', 
    action: () => console.log('报表生成功能')
  },
  { 
    label: '告警中心', 
    value: '正常', 
    action: () => console.log('告警中心功能')
  },
  { 
    label: '配置中心', 
    value: '已更新', 
    action: () => console.log('配置中心功能')
  },
  { 
    label: '日志查看', 
    value: '实时', 
    action: () => console.log('日志查看功能')
  },
  { 
    label: '性能优化', 
    value: '优秀', 
    action: () => console.log('性能优化功能')
  }
])

const getTime = () => {
  currentTime.value = new Date().toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  })
}

// 返回到主界面
const goBack = () => {
  router.push('/')
}

// 智能缩放系统 - 保持布局不变
const adjustPageScale = () => {
  const container = document.querySelector('.data-screen') as HTMLElement
  if (!container) return
  
  const windowWidth = window.innerWidth
  const windowHeight = window.innerHeight
  const designWidth = 1920
  const designHeight = 1080
  
  // 计算缩放比例，设置最小缩放限制
  const scaleX = windowWidth / designWidth
  const scaleY = windowHeight / designHeight
  const scale = Math.max(0.3, Math.min(scaleX, scaleY)) // 最小缩放到30%
  
  // 应用缩放
  container.style.transform = `scale(${scale})`
  container.style.transformOrigin = 'top left'
  
  // 调整容器位置使其居中
  const scaledWidth = designWidth * scale
  const scaledHeight = designHeight * scale
  const offsetX = (windowWidth - scaledWidth) / 2
  const offsetY = (windowHeight - scaledHeight) / 2
  
  container.style.left = `${Math.max(0, offsetX)}px`
  container.style.top = `${Math.max(0, offsetY)}px`
}

onMounted(() => {
  getTime()
  setInterval(() => {
    getTime()
  }, 1000)
  
  // 初始化缩放
  adjustPageScale()
  
  // 监听窗口大小变化
  window.addEventListener('resize', adjustPageScale)
})

onUnmounted(() => {
  window.removeEventListener('resize', adjustPageScale)
})



</script>

<style scoped>
.screen-wrapper {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
  overflow: hidden;
  position: relative;
}

/* 流动背景动画层 */
.screen-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(circle at 20% 30%, rgba(0, 212, 255, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(91, 141, 239, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 40% 80%, rgba(255, 255, 0, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 90% 20%, rgba(255, 107, 107, 0.1) 0%, transparent 50%);
  animation: flowingBackground 20s ease-in-out infinite;
  z-index: 1;
}

/* 粒子效果层 */
.screen-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(2px 2px at 20px 30px, rgba(0, 212, 255, 0.5), transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(91, 141, 239, 0.4), transparent),
    radial-gradient(1px 1px at 90px 40px, rgba(255, 255, 0, 0.6), transparent),
    radial-gradient(1px 1px at 130px 80px, rgba(255, 107, 107, 0.4), transparent),
    radial-gradient(2px 2px at 160px 30px, rgba(0, 255, 136, 0.5), transparent);
  background-repeat: repeat;
  background-size: 200px 100px;
  animation: particleFloat 15s linear infinite;
  z-index: 2;
}

.data-screen {
  width: 1920px;
  height: 1080px;
  background: linear-gradient(135deg, rgba(11, 11, 12, 0.8) 0%, rgba(11, 11, 83, 0.8) 50%, rgba(22, 33, 62, 0.8) 100%);
  color: #fff;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  transform-origin: top left;
  z-index: 10;
  backdrop-filter: blur(1px);
}

/* 头部样式 */
.screen-header {
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 20px 0;
  backdrop-filter: blur(10px);
}

.header-content {
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-title {
  font-size: 32px;
  font-weight: bold;
  background: linear-gradient(45deg, #00d4ff, #5b8def, #ffff00, #ff6b6b, #00ff88);
  background-size: 300% 300%;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
  animation: titleColorFlow 8s ease-in-out infinite;
  text-shadow: 0 0 30px rgba(0, 212, 255, 0.3);
}

.header-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.back-btn {
  padding: 8px 16px;
  background: rgba(0, 212, 255, 0.2);
  border: 1px solid rgba(0, 212, 255, 0.5);
  border-radius: 6px;
  color: #00d4ff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  font-weight: 500;
}

.back-btn:hover {
  background: rgba(0, 212, 255, 0.3);
  border-color: #00d4ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
}

.current-time {
  font-size: 20px;
  font-weight: bold;
  color: #00d4ff;
  text-shadow: 0 0 10px rgba(0, 212, 255, 0.6);
  animation: timePulse 3s ease-in-out infinite;
}

.refresh-time {
  font-size: 14px;
  color: #999;
}

/* 主要内容样式 */
.screen-content {
  width: 100%;
  height: calc(1080px - 100px);
  padding: 15px;
  display: flex;
  gap: 15px;
  align-items: stretch;
  box-sizing: border-box;
}

/* 左侧图表区域 */
.left-charts {
  flex: 3;
  display: flex;
  flex-direction: column;
  gap: 15px;
  height: 100%;
  align-items: stretch;
}

/* 中间数字卡片区域 */
.center-content {
  flex: 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0px;
  gap: 15px;
  height: 100%;
}
/* 右侧内容区域 */
.right-content {
  padding-top: 0px;
  flex: 3;
  display: flex;
  flex-direction: column;
  gap: 15px;
  height: 100%;
  align-items: stretch;
}

/* 环形图容器 */
.pie-charts-container {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 12px;
  padding: 15px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* 环形图网格布局 */
.pie-charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  flex: 1;
  align-items: center;
}



/* 顶部卡片样式 */
.top-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.card-icon-custom {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.users { background: linear-gradient(135deg, #5470c6, #3d5afe); }
.active { background: linear-gradient(135deg, #91cc75, #66bb6a); }
.problems { background: linear-gradient(135deg, #fac858, #ffa726); }
.submissions { background: linear-gradient(135deg, #ee6666, #ef5350); }

/* 中间图表区域 */
.middle-charts {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

.chart-left,
.chart-center,
.chart-right {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.chart-container {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  backdrop-filter: blur(10px);
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 15px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.gauge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* 通过率样式 */
.pass-rate-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.pass-rate-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pass-rate-label {
  min-width: 80px;
  font-size: 14px;
  color: #ccc;
}

.pass-rate-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.pass-rate-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease;
}

.pass-rate-value {
  min-width: 40px;
  text-align: right;
  font-weight: bold;
  color: #fff;
}

/* 底部区域样式 */
.bottom-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 15px;
}

.realtime-data,
.system-status {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  backdrop-filter: blur(10px);
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 20px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* 实时日志样式 */
.data-stream {
  max-height: 200px;
  overflow-y: auto;
}

.log-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
}

.log-item.new-log {
  background: rgba(0, 212, 255, 0.1);
  border-radius: 6px;
  padding: 8px 10px;
  animation: slideIn 0.5s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.log-time {
  font-size: 12px;
  color: #999;
  min-width: 80px;
}

.log-type {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  min-width: 50px;
  text-align: center;
}

.log-type.success { background: rgba(145, 204, 117, 0.2); color: #91cc75; }
.log-type.info { background: rgba(84, 112, 198, 0.2); color: #5470c6; }
.log-type.warning { background: rgba(238, 102, 102, 0.2); color: #ee6666; }

.log-message {
  flex: 1;
  font-size: 14px;
  color: #ccc;
}

/* 系统状态样式 */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.status-indicator.online {
  background: #91cc75;
  box-shadow: 0 0 10px rgba(145, 204, 117, 0.5);
}

.status-indicator.warning {
  background: #fac858;
  box-shadow: 0 0 10px rgba(250, 200, 88, 0.5);
}

.status-indicator.offline {
  background: #ee6666;
  box-shadow: 0 0 10px rgba(238, 102, 102, 0.5);
}

.status-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-name {
  font-size: 14px;
  color: #ccc;
}

.status-value {
  font-size: 12px;
  color: #999;
}

/* 移除响应式布局变化，保持固定的三列布局 */

@media (max-width: 1200px) {
  .pie-charts-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
  }
}

@media (max-width: 768px) {
  .screen-content {
    padding: 20px;
    flex-direction: column;
  }
  
  .left-charts,
  .center-content,
  .right-content {
    width: 100%;
  }
  
  .center-content {
    padding: 0;
  }
  

  
  .pie-charts-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  
  .pie-charts-container {
    padding: 15px;
  }
  
  .header-content {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }
  
  .main-title {
    font-size: 24px;
  }
}

@media (max-width: 480px) {
  .pie-charts-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
}

/* 流动背景动画 */
@keyframes flowingBackground {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  25% {
    transform: translate(-45%, -55%) rotate(90deg);
  }
  50% {
    transform: translate(-55%, -45%) rotate(180deg);
  }
  75% {
    transform: translate(-60%, -50%) rotate(270deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* 粒子漂浮动画 */
@keyframes particleFloat {
  0% {
    transform: translateY(0px) translateX(0px);
    opacity: 0.7;
  }
  33% {
    transform: translateY(-20px) translateX(10px);
    opacity: 1;
  }
  66% {
    transform: translateY(-10px) translateX(-5px);
    opacity: 0.8;
  }
  100% {
    transform: translateY(0px) translateX(0px);
    opacity: 0.7;
  }
}

/* 增强的边框发光动画 */
@keyframes enhancedBorderGlow {
  0% {
    background-position: 0% 50%;
    filter: hue-rotate(0deg);
  }
  25% {
    background-position: 50% 0%;
    filter: hue-rotate(90deg);
  }
  50% {
    background-position: 100% 50%;
    filter: hue-rotate(180deg);
  }
  75% {
    background-position: 50% 100%;
    filter: hue-rotate(270deg);
  }
  100% {
    background-position: 0% 50%;
    filter: hue-rotate(360deg);
  }
}

/* 标题颜色流动动画 */
@keyframes titleColorFlow {
  0% {
    background-position: 0% 50%;
  }
  25% {
    background-position: 50% 0%;
  }
  50% {
    background-position: 100% 50%;
  }
  75% {
    background-position: 50% 100%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* 时间脉冲动画 */
@keyframes timePulse {
  0%, 100% {
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.6);
    transform: scale(1);
  }
  50% {
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.9), 0 0 30px rgba(0, 212, 255, 0.4);
    transform: scale(1.02);
  }
}
</style>